package com.hot12345.service;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class LoginService {

	private final static Log log = LogFactory.getLog(LoginService.class);
	/**
	 * 判断是否在线，cookie判断
	 *	
	 * @param request
	 * @return
	 * @author wuzongbao
	 * @date 2013-5-10 上午12:08:23
	 * @version V1.0
	 */
	public static boolean isOnline(HttpServletRequest request){
		Cookie[] cookies = request.getCookies();//这样便可以获取一个cookie数组
		if(cookies==null){
			return false;
		}
		for(Cookie cookie : cookies){
		    log.debug("cookie.name=" + cookie.getName());// get the cookie name
		    log.debug("cookie.getValue=" + cookie.getValue()); // get the cookie value
		    if("userName".equals(cookie.getName()) && !"".equals(cookie.getValue()) && !"null".equals(cookie.getValue()) && cookie.getValue()!=null){
		    	return true;
		    }
		}
		
		return false;
	}
}
